package com.cn.mmd.controller;

import com.cn.mmd.model.*;
import com.cn.mmd.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 学生评价接口
 * Created by Administrator on 2016/12/9.
 */

@Controller
@RequestMapping(value="EvaluateByStudent")
public class EvaluateByStudentController {
    @Autowired
    StuCourseLabelService stuCourseLabelService;
    @Autowired
    LabelService labelService;
    @Autowired
    LeadershipService leadershipService;
    @Autowired
    TokenController tokenController;
    @Autowired
    StudentService studentService;
    @Autowired
    TeacherService teacherService;
    @Autowired
    EvaluateTeacherService evaluateTeacherService;
    @Autowired
    MajorCourseNumController majorCourseNumController;
    @Autowired
    LogController logController;
    @Autowired
    private StudentIntegralController studentIntegralController;
    @Autowired
    private CourseService courseService;
    @Autowired
    private StudentCountService studentCountService;
    @Autowired
    private StudentCountController studentCountController;

    /**
     * 学生查看要进行评价的教师列表
     * @throws com.alibaba.fastjson.JSONException
     */
    @RequestMapping(value = "pushLabelToStudent")
    public synchronized @ResponseBody
    Map<String,Object> pushLabelToStudent(HttpServletRequest request)throws Exception {
        Map<String,Object> map=new HashMap<String, Object>();
        Map<String,Object> map1=null;
        List<Map> mapList=new ArrayList<Map>();

//        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可以方便地修改日期格式
//        String nowTime = dateFormat.format( now );//时间
        Calendar c = Calendar.getInstance();
        c.add(Calendar.HOUR, - 48);
        Date lastTime = c.getTime();
        String pushTime = dateFormat.format(lastTime);//当前时间的48小时前
        String studentId=request.getParameter("studentId");//学生id

        String token = request.getParameter("token");
        //System.out.println("进入学生评价");

        StudentApp studentApp;
        studentApp = (StudentApp) tokenController.token1(studentId, token);
        if (studentApp == null) {
            map.put("code", 202);
            map.put("message", "您暂无权限做此操作");
           // map.put("data", "");
            return map;
        }

        Student student=studentService.selectByKey(studentId);
        String studentClass=student.getStudentclass();//班级

        StuCourseLabel stuCourseLabel=new StuCourseLabel();
        stuCourseLabel.setStudentclass(studentClass);
        stuCourseLabel.setPushtime(pushTime);//推送时间

        List<StuCourseLabel> stuCourseLabelList=stuCourseLabelService.selectTwoDaysByStudentId(stuCourseLabel);

        if (stuCourseLabelList.size()>0){

            for (StuCourseLabel stuCourseLabel1:stuCourseLabelList){

                map1=new HashMap<String, Object>();

                map1.put("pushId",stuCourseLabel1.getPushid());//做主键的推送id
                map1.put("teacherId",stuCourseLabel1.getTeacherid());//教师id
                map1.put("teacherName",stuCourseLabel1.getTeachername());//教师名
                map1.put("HeadPortrait",stuCourseLabel1.getTeacherheadportrait());//教师头像
                map1.put("courseId",stuCourseLabel1.getCourseid());//课程id
                map1.put("courseName",stuCourseLabel1.getCoursename());//课程名
                map1.put("twoIndexName",stuCourseLabel1.getTwoindexname());//推送的二级指标
                map1.put("pushTime",stuCourseLabel1.getPushtime());//推送时间
//                map1.put("labelState",stuCourseLabel1.getLabelstate());//标签的状态（已填写1或是未填写2）
//                map1.put("submitTime",stuCourseLabel1.getSubmittime());//提交时间 如果状态为1，则有时间，如果状态为2，则为空null

                mapList.add(map1);
            }
            map.put("code", 200);
            map.put("message", "教师列表查询成功");
            map.put("data", mapList);
        }else {

            map.put("code", 201);
            map.put("message", "暂无要评价的老师");
//            map.put("data", mapList);
        }

        return map;
    }



    /**
     * 查看推送的标签详情
     * @throws com.alibaba.fastjson.JSONException
     */
    @RequestMapping(value = "pushLabelParticulars")
    public synchronized @ResponseBody
    Map<String,Object> pushLabelParticulars(HttpServletRequest request)throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        List<String> list=null;
        Map<String,Object> map1=null;
        Map<String,Object> map2=null;
        Map<String,Object> map3=new HashMap<String, Object>();
        List<Map> mapList=new ArrayList<Map>();
        List<Map> mapList1=new ArrayList<Map>();

        String studentId=request.getParameter("studentId");//学生id
        String twoIndexName=request.getParameter("twoIndexName");//推送的二级指标
        int pushId=Integer.parseInt(request.getParameter("pushId"));//推送id

        String token = request.getParameter("token");
        //System.out.println("进入学生评价");

        StudentApp studentApp;
        studentApp = (StudentApp) tokenController.token1(studentId, token);
        if (studentApp == null) {
            map.put("code", 202);
            map.put("message", "您暂无权限做此操作");
           // map.put("data", "");
            return map;
        }

        Label label=new Label();
        label.setTwoindexname(twoIndexName);
        List<Label> labelList=labelService.selectByThreeLabelName(label);
        if (labelList.size()>0){

            for (int a=0;a<labelList.size();a++){
                list=new ArrayList<String>();
                map1=new HashMap<String, Object>();
                for (int b=labelList.size()-1;b>a;b--){

                    if (labelList.get(a).getThreeindexname().equals(labelList.get(b).getThreeindexname())){
                        list.add(labelList.get(b).getLabelname());
//                        System.out.println("list的长度b"+list.size());
                        labelList.remove(b);
                    }

                }
                list.add(labelList.get(a).getLabelname());
//                System.out.println("list的长度a"+list.size()+"   标签a："+labelList.get(a).getLabelname());

                map1.put("threeIndexName", labelList.get(a).getThreeindexname());//三级指标
                map1.put("threeIndexQuestion",labelList.get(a).getThreeindexquestion());//三级指标问题
                map1.put("label",list);

                mapList.add(map1);

//                labelList.remove(a);
            }

            StudentPushLabel studentPushLabel=new StudentPushLabel();
            studentPushLabel.setStudentid(studentId);
            studentPushLabel.setPushid(pushId);

            List<StudentPushLabel> studentPushLabelList=stuCourseLabelService.selectStudentPushLabel(studentPushLabel);//查出该学生是否有答过此次推送的题

//            System.out.println("答过吗？？"+studentPushLabelList.size());

            if (studentPushLabelList.size()>0){// 该二级指标已被填写 答过
                for (StudentPushLabel studentPushLabel1:studentPushLabelList) {
                    StudentEvaluate studentEvaluate = new StudentEvaluate();
                    studentEvaluate.setStudentid(studentId);
                    studentEvaluate.setEvaluatetime(studentPushLabel1.getSubmittime());

                    List<StudentEvaluate> studentEvaluateList = leadershipService.selectAllStudentEvaluate(studentEvaluate);

//                    System.out.println("studentEvaluateList："+studentEvaluateList.size());

                    for (StudentEvaluate studentEvaluate1 : studentEvaluateList) {

                        String[] evaluateLabels = studentEvaluate1.getEvaluatelabel().split(",");
                        for (int c = 0; c < evaluateLabels.length; c++) {
                            map2 = new HashMap<String, Object>();

                            String threeIndexName = evaluateLabels[c].split("!")[1];//三级指标
                            String evaLabel = evaluateLabels[c].split("!")[2];//标签

                            map2.put("evaluateThreeIndex", threeIndexName);
                            map2.put("evaluateLabel", evaLabel);

                            mapList1.add(map2);
                        }

                    }
                }
            }
//            else{
//                map2=new HashMap<String, Object>();
//
//                map2.put("threeIndexName","");
//                map2.put("evaluateLabel","");
//
//                mapList1.add(map2);
//            }

            map3.put("pushLabel",mapList);//推送的标签
            map3.put("submitLabel",mapList1);//提交的标签

            map.put("code", 200);
            map.put("message", "查询成功");
            map.put("data", map3);

        }else {

            map.put("code", 201);
            map.put("message", "标签查询失败");
//            map.put("data", map3);
        }

        return map;
    }



    /**
     * 学生对老师进行标签评价
     *
     * @param request
     * @return
     *
     *
     */
    @RequestMapping(value = "evaluationStudent")
    public synchronized
    @ResponseBody
    Map<String, Object> evaluationStudent(HttpServletRequest request) throws Exception{
        Map<String, Object> map = new HashMap<String, Object>();
//        List labelTopList=null;

        String studentId = request.getParameter("studentId");//前端传入评价人id
        String byEvaluatePersonId = request.getParameter("byEvaluatePersonId");//前端传入被评价人id
        String evaluateLabel = request.getParameter("evaluateLabel");//前端传入所选标签内容
        int pushId =Integer.parseInt(request.getParameter("pushId"));//推送id
        String pushTime = request.getParameter("pushTime");//推送时间

        String courseId=request.getParameter("courseId");//课程id
        String courseName=request.getParameter("courseName");//课程名

        String token = request.getParameter("token");
        //System.out.println("进入学生评价");

        StudentApp studentApp;
        studentApp = (StudentApp) tokenController.token1(studentId, token);
        if (studentApp == null) {
            map.put("code", 211);
            map.put("message", "您暂无权限做此操作");
          //  map.put("data", "");
            return map;
        }

        List<String> thisLabel=new ArrayList<String>();
        Student student = studentService.selectByPrimaryKey(studentId);

        Teacher teachers = teacherService.serlectTeacher(byEvaluatePersonId);//查出该老师属于哪个学校和学院

        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
        String nowTime = dateFormat.format( now );//时间

        long weekNum=0;
        int dayForWeek1 = 0;

        //这里需要计算获取  ！！！查出第几周，周几！
        TermBeginsTime termBeginsTime=evaluateTeacherService.selectTermBeginsTime();//查出开学时间

        if (termBeginsTime!=null){
            String termTime=termBeginsTime.getTermbeginstime();

            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

            Date a1 = format .parse(nowTime);
//            System.out.println("a1:"+a1);
            Date b1 = format .parse(termTime);
//            System.out.println("b1:"+b1);
//获取相减后周数
            weekNum = (a1.getTime()-b1.getTime())/(7*24*60*60*1000)+1;
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(format.parse(nowTime));
            c2.setTime(format.parse(termTime));
            if(c1.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek1 = 7;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 2){
                dayForWeek1 = 1;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 3){
                dayForWeek1 = 2;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 4){
                dayForWeek1 = 3;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 5){
                dayForWeek1 = 4;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 6){
                dayForWeek1 = 5;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 7){
                dayForWeek1 = 6;
            }

            int dayForWeek2 = 0;
            if(c2.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek2 = 7;
            }else{
                dayForWeek2 = c2.get(Calendar.DAY_OF_WEEK) - 1;
            }
            if (dayForWeek1<dayForWeek2){
                weekNum=weekNum+1;
            }
        }
        System.out.println("现在是第"+weekNum+"周");

        Course course=courseService.selectByKey(courseId);
        System.out.println(studentId + "：" + student + "===" + byEvaluatePersonId+"："+teachers+"==="+courseId+"："+course);
        if (student==null||teachers==null||course==null){
            map.put("code", 208);
            map.put("message", "查询无结果");
            return map;
        }


        String[] evaluate = evaluateLabel.split(",");//传入的标签label:{"标签库名！三级指标名！标签"，"标签库名！三级指标名！标签"...}

        List<Label> labelList = new ArrayList<Label>();
        for (int a = 0; a < evaluate.length; a++) {
            String[] label = evaluate[a].split("!");

            String packageName = label[0];
            String threeIndexName = label[1];
            String labelName = label[2];

            thisLabel.add(labelName);
            //System.out.println(indexName + "======" + labelName);

            Label label2 = new Label();
            label2.setPackagelabel(packageName);
            label2.setLabelname(labelName);
            // label2.setIndexname(indexName);

            Label label1 = evaluateTeacherService.selectAllLabel(label2);//查出一个标签属于哪个指标，分值多少
            if (label1 != null) {
                labelList.add(label1);
            } else {
                map.put("code", 202);
                map.put("message", "查询标签失败");
//                map.put("data", null);
                return map;
            }
        }



        List<LabelThreeIndex> labelThreeIndexes = new ArrayList<LabelThreeIndex>();
        // Float avg=0f;
        for (int l = 0; l < labelList.size(); l++) {
            List<Float> score = new ArrayList<Float>();
            for (int m = labelList.size() - 1; m > l; m--) {
                if (labelList.get(l).getIndexname().equals(labelList.get(m).getIndexname()) &&
                        labelList.get(l).getTwoindexname().equals(labelList.get(m).getTwoindexname()) &&
                        labelList.get(l).getThreeindexname().equals(labelList.get(m).getThreeindexname())) {

                    score.add(labelList.get(m).getLabelgrade());//得到同一个三级指标下的所有标签
                    labelList.remove(m);

                }
            }
            score.add(labelList.get(l).getLabelgrade());
            Float sum = 0f;
            for (Float s : score) {
                sum += s;
            }
            // System.out.println("和：" + sum + "====标签数：" + score.size());
            Float avg = sum / score.size();//求平均分
            //Float avg1 =   (float)(Math.round(avg*10))/10;
            //System.out.println("到这个出问题！！"+labelList.get(l).getThreeindexname());


            LabelThreeIndex threeIndex = new LabelThreeIndex();
            threeIndex.setThreeindexname(labelList.get(l).getThreeindexname());
            threeIndex.setPackagelabel(labelList.get(l).getPackagelabel());

            LabelThreeIndex labelThreeIndex = evaluateTeacherService.selectByThreeIndexName(threeIndex);
            if (labelThreeIndex != null) {
                // System.out.println(labelThreeIndex.getThreeindexname() + "===" + labelThreeIndex.getProportion());
                Float threeIndexScore = avg * labelThreeIndex.getProportion();//乘以权重  得出该三级指标得分

                LabelThreeIndex labelThreeIndex1 = new LabelThreeIndex();
                labelThreeIndex1.setThreeindexname(labelList.get(l).getThreeindexname());
                labelThreeIndex1.setTwoindexname(labelList.get(l).getTwoindexname());
                labelThreeIndex1.setIndexname(labelList.get(l).getIndexname());
                labelThreeIndex1.setPackagelabel(labelList.get(l).getPackagelabel());//！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
                labelThreeIndex1.setThreeIndexScore(threeIndexScore);
                // System.out.println("三级指标：" + labelList.get(l).getThreeindexname() + "---得分：" + threeIndexScore);
                labelThreeIndexes.add(labelThreeIndex1);//存入一个list labelThreeIndexes中，里面全部为不同三级指标的得分
            } else {
                map.put("code", 203);
                map.put("message", "查询三级指标失败");
//                map.put("data", null);
                return map;
            }
        }
        //循环比较二级指标下的标签,算出第二级指标的得分

        List<LabelTwoIndex> labelTwoIndexes = new ArrayList<LabelTwoIndex>();
        for (int l = 0; l < labelThreeIndexes.size(); l++) {
            List<Float> score = new ArrayList<Float>();
            for (int m = labelThreeIndexes.size() - 1; m > l; m--) {
                if (labelThreeIndexes.get(l).getIndexname().equals(labelThreeIndexes.get(m).getIndexname()) &&
                        labelThreeIndexes.get(l).getTwoindexname().equals(labelThreeIndexes.get(m).getTwoindexname())) {
                    score.add(labelThreeIndexes.get(m).getThreeIndexScore());//得到同一个二级指标下的所有三级指标
                    labelThreeIndexes.remove(m);
                }
            }
            score.add(labelThreeIndexes.get(l).getThreeIndexScore());
            Float sum = 0f;
            for (Float s : score) {
                sum += s;
            }
            //  System.out.println(labelThreeIndexes.get(l).getTwoindexname() + "-的和：" + sum+"         "+labelThreeIndexes.get(l).getPackagelabel());
            LabelTwoIndex twoIndex = new LabelTwoIndex();
            twoIndex.setTwoindexname(labelThreeIndexes.get(l).getTwoindexname());
            twoIndex.setPackagelabel(labelThreeIndexes.get(l).getPackagelabel());

            LabelTwoIndex labelTwoIndex = evaluateTeacherService.selectByTwoIndexName(twoIndex);
            if (labelTwoIndex != null) {
//                Float twoIndexScore = sum * labelTwoIndex.getProportion();
                LabelTwoIndex labelTwoIndex1 = new LabelTwoIndex();
                labelTwoIndex1.setIndexname(labelTwoIndex.getIndexname());
                labelTwoIndex1.setTwoindexname(labelTwoIndex.getTwoindexname());
                labelTwoIndex1.setPackagelabel(labelTwoIndex.getPackagelabel());
                labelTwoIndex1.setTwoindexscore(sum);//二级指标得分（未乘以权重）


                labelTwoIndexes.add(labelTwoIndex1);//存入一个list labelTwoIndexes，里面全部为不同二级指标的得分
            } else {
                map.put("code", 204);
                map.put("message", "查询二级指标失败");
//                map.put("data", null);
                return map;
            }
        }

//        Date now = new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
        String evaluateTime = dateFormat.format(now);//时间


        Float twoIndexScore = 0f;
        String indexScore="";
//        List<String> twoList=new ArrayList<String>();
        for (LabelTwoIndex s : labelTwoIndexes) {
            twoIndexScore =(float)(Math.round(s.getTwoindexscore()*100))/100;//传入的二级指标得分  从这里！！！！！！！！！！！！！！！！！！！！！！！！！！！！
//            twoList.add(s.getTwoindexname());
            if (indexScore.equals("")){
                indexScore= s.getPackagelabel() + "!" + s.getTwoindexname() + "!" + twoIndexScore;//这次评价的二级指标得分
            }else {
                indexScore=indexScore +","+ s.getPackagelabel() + "!" + s.getTwoindexname() + "!" + twoIndexScore;
            }
//            twoIndexScore+=twoIndexScore;
        }


        //将此次评价分数整合或添加到被评价人的的排名表中
//            Float sum = 0f;
        TeacherRanking teacherRanking = teacherService.selectTeacherRanking(byEvaluatePersonId);

        if (teacherRanking != null) {
            TeacherRanking teacherRanking1 = new TeacherRanking();//到这里！！！！添加进排名表~~~~~~~~~~~~~~~~·
            teacherRanking1.setTeacherid(byEvaluatePersonId);


            String Twoindexscore1="";
            String studentTwoindexscore1="";
            String[] indexScores=indexScore.split(",");
            for (int c=0;c<indexScores.length;c++) {
                String twoIndexName = indexScores[c].split("!")[1];//这次评价的二级指标名
                float twoScore = Float.parseFloat(indexScores[c].split("!")[2]);//二级指标得分
                if (teacherRanking.getTwoindexscore() != null) {

                    String[] Twoindexscores = teacherRanking.getTwoindexscore().split("!!");//该老师在排名表中已经有的二级指标；双感叹号分割
                    String[] studentTwoindexscores = teacherRanking.getStudenttwoindexscore().split("!!");//学生评价已有的二级指标；双感叹号分割

                    List<String> list=new ArrayList<String>();
                    List<String> list1=new ArrayList<String>();

                    //该老师总的二级指标评价统计
                    for (int a = 0; a < Twoindexscores.length; a++) {
                        String[] Twoindexscore = Twoindexscores[a].split("_");
                        String twoIndex = Twoindexscore[0];//已有的二级指标名
                        float score = Float.parseFloat(Twoindexscore[1]);//总分数
                        int number = Integer.parseInt(Twoindexscore[2]);//总人数

                        list.add(twoIndex);

                        if (twoIndex.equals(twoIndexName)) {
                            score = score + twoScore;
                            number = number + 1;

                            if (Twoindexscore1.equals("")) {
                                Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                            } else {
                                Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                            }
                        }else {
                            if (Twoindexscore1.equals("")) {
                                Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                            } else {
                                Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                            }
                        }
                    }
                    if (!list.contains(twoIndexName)){
                        if (Twoindexscore1.equals("")) {
                            Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                        } else {
                            Twoindexscore1 = Twoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                        }
                    }

                    //学生评价二级指标统计
                    for (int a = 0; a < studentTwoindexscores.length; a++) {
                        String[] Twoindexscore = studentTwoindexscores[a].split("_");
                        String twoIndex = Twoindexscore[0];//已有的学生评价二级指标名
                        float score = Float.parseFloat(Twoindexscore[1]);//总分数
                        int number = Integer.parseInt(Twoindexscore[2]);//总人数

                        list1.add(twoIndex);

                        if (twoIndex.equals(twoIndexName)) {
                            score = score + twoScore;
                            number = number + 1;

                            if (studentTwoindexscore1.equals("")) {
                                studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                            } else {
                                studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                            }
                        }else {
                            if (studentTwoindexscore1.equals("")) {
                                studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                            } else {
                                studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                            }
                        }
                    }
                    if (!list1.contains(twoIndexName)){
                        if (studentTwoindexscore1.equals("")) {
                            studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                        } else {
                            studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                        }
                    }
                    //

                } else {
                    Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                    studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                }
            }

            String [] Twoindexscores2=Twoindexscore1.split("!!");

            List<LabelTwoIndex> labelTwoIndexList=new ArrayList<LabelTwoIndex>();
            for (int d=0;d<Twoindexscores2.length;d++){

                String twoIndexName=Twoindexscores2[d].split("_")[0];//二级指标名
                float twoIndexScore1=Float.parseFloat(Twoindexscores2[d].split("_")[1])/Integer.parseInt(Twoindexscores2[d].split("_")[2]);//二级指标得分
                LabelTwoIndex labelTwoIndex=new LabelTwoIndex();
                labelTwoIndex.setTwoindexname(twoIndexName);
                labelTwoIndex.setPackagelabel("教评");

                LabelTwoIndex labelTwoIndex1=evaluateTeacherService.selectByTwoIndexName(labelTwoIndex);
//                float twoIndexScore2=twoIndexScore1*labelTwoIndex1.getProportion();

                labelTwoIndex1.setTwoindexscore(twoIndexScore1);

                labelTwoIndexList.add(labelTwoIndex1);
            }//这里！！！！！

            String haveAlready=teacherRanking.getMylabelrank();

            float sum=majorCourseNumController.EvaluateScore(labelTwoIndexList);//调用封装的方法  计算得分

            Map m=majorCourseNumController.LabelNumber(haveAlready,evaluateLabel);//该老师评价的top：标签_数量

            String labelTop=(String)m.get("newLabel");
//            labelTopList=(List)m.get("labelTopList");

            teacherRanking1.setTwoindexscore(Twoindexscore1);//该老师总二级指标-得分
            teacherRanking1.setStudenttwoindexscore(studentTwoindexscore1);//学生评价二级指标-得分
            teacherRanking1.setMylabelrank(labelTop);//该老师评价的top：标签_数量

            teacherRanking1.setTeacheravg(sum);//二级指标平均分

            int a = teacherService.updateTeacherRanking(teacherRanking1);
            if (a > 0) {
                //System.out.println("成功");
            } else {
                map.put("code", 206);
                map.put("message", "整合教师排名失败");
//                map.put("data", null);
                return map;
            }
        } else {
            String[] indexScores=indexScore.split(",");

            String twoIndexScoreN="";
            float sum=0f;
            for (int e=0;e<indexScores.length;e++){

                String twoIndexName = indexScores[e].split("!")[1];//二级指标名
                float twoScore = Float.parseFloat(indexScores[e].split("!")[2]);//二级指标得分

                sum+=twoScore;
                if (twoIndexScoreN.equals("")){
                    twoIndexScoreN=twoIndexName+"_"+twoScore+"_"+1;
                }else {
                    twoIndexScoreN=twoIndexScoreN+"!!"+twoIndexName+"_"+twoScore+"_"+1;
                }
            }
            float avg=(float)Math.round(sum/indexScores.length*100)/100;
            String newLabel="";
            for (int f=0;f<thisLabel.size();f++){
                if (newLabel.equals("")){
                    newLabel=thisLabel.get(f)+"_"+1;
                }else {
                    newLabel=newLabel+"!!"+thisLabel.get(f)+"_"+1;
                }
            }

            TeacherRanking teacherRanking1 = new TeacherRanking();
            teacherRanking1.setTeacherid(byEvaluatePersonId);
            teacherRanking1.setTwoindexscore(twoIndexScoreN);
            teacherRanking1.setStudenttwoindexscore(twoIndexScoreN);
            teacherRanking1.setMylabelrank(newLabel);
            teacherRanking1.setTeacheravg(avg);  //  这里！！！！！！！！！！

            int a = teacherService.insertTeacherRanking(teacherRanking1);

            if (a > 0) {
                //System.out.println("成功");
            } else {
                map.put("code", 206);
                map.put("message", "整合教师排名失败");
//                map.put("data", "");
                return map;
            }
        }
        //还要将此次评价分数整合到avg_school表和avg_college表中！！！！！！！！！！！！
//          Teacher teachers = teacherService.serlectTeacher(byEvaluatePersonId);//查出该老师属于哪个学校和学院
        //将此次评价分数整合到avg_school表
        AvgSchool avgSchool = teacherService.selectAvgSchool(); // 这里！！！！！！！！！！！！！！！！！！！！！！1
        if (avgSchool != null) {
            if (teachers != null) {

                String Twoindexscore1="";
                String studentTwoindexscore1="";
                String[] indexScores=indexScore.split(",");
                for (int c=0;c<indexScores.length;c++) {
                    String twoIndexName = indexScores[c].split("!")[1];//这次评价的二级指标名
                    float twoScore = Float.parseFloat(indexScores[c].split("!")[2]);//二级指标得分
                    if (avgSchool.getTwoindexscore() != null) {

                        String[] Twoindexscores = avgSchool.getTwoindexscore().split("!!");//学校表中已经有的二级指标；双感叹号分割
                        String[] studentTwoindexscores = avgSchool.getStutwoindexscore().split("!!");//学生评价已有的二级指标；双感叹号分割

                        List<String> list=new ArrayList<String>();
                        List<String> list1=new ArrayList<String>();

                        //学校总的二级指标评价统计
                        for (int a = 0; a < Twoindexscores.length; a++) {
                            String[] Twoindexscore = Twoindexscores[a].split("_");
                            String twoIndex = Twoindexscore[0];//已有的二级指标名
                            float score = Float.parseFloat(Twoindexscore[1]);//总分数
                            int number = Integer.parseInt(Twoindexscore[2]);//总人数

                            list.add(twoIndex);

                            if (twoIndex.equals(twoIndexName)) {
                                score = score + twoScore;
                                number = number + 1;

                                if (Twoindexscore1.equals("")) {
                                    Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }else {
                                if (Twoindexscore1.equals("")) {
                                    Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }
                        }
                        if (!list.contains(twoIndexName)){
                            if (Twoindexscore1.equals("")) {
                                Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                            } else {
                                Twoindexscore1 = Twoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                            }
                        }
                        //学校学生评价的二级指标评价统计
                        for (int a = 0; a < studentTwoindexscores.length; a++) {
                            String[] Twoindexscore = studentTwoindexscores[a].split("_");
                            String twoIndex = Twoindexscore[0];//已有的学生评价二级指标名
                            float score = Float.parseFloat(Twoindexscore[1]);//总分数
                            int number = Integer.parseInt(Twoindexscore[2]);//总人数

                            list1.add(twoIndex);

                            if (twoIndex.equals(twoIndexName)) {
                                score = score + twoScore;
                                number = number + 1;

                                if (studentTwoindexscore1.equals("")) {
                                    studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }else {
                                if (studentTwoindexscore1.equals("")) {
                                    studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }
                        }
                        if (!list1.contains(twoIndexName)){
                            if (studentTwoindexscore1.equals("")) {
                                studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                            } else {
                                studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                            }
                        }

                    } else {
                        Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                        studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                    }
                }

                AvgSchool avgSchool1 = new AvgSchool();
                avgSchool1.setSchoolid(teachers.getTeacherschool());
                avgSchool1.setTwoindexscore(Twoindexscore1);
                avgSchool1.setStutwoindexscore(studentTwoindexscore1);

                int a = teacherService.updateAvgSchool(avgSchool1);
                if (a <= 0)  {
                    map.put("code", 207);
                    map.put("message", "修改学校平均分失败");
//                    map.put("data", "");
                    return map;
                }
            } else {
                map.put("code", 208);
                map.put("message", "学校查询失败");
//                map.put("data", "");
                return map;
            }
        } else {

            if (teachers != null) {

                String[] indexScores=indexScore.split(",");
                String twoIndexScoreN="";
                for (int e=0;e<indexScores.length;e++){

                    String twoIndexName = indexScores[e].split("!")[1];//二级指标名
                    float twoScore = Float.parseFloat(indexScores[e].split("!")[2]);//二级指标得分

                    if (twoIndexScoreN.equals("")){
                        twoIndexScoreN=twoIndexName+"_"+twoScore+"_"+1;
                    }else {
                        twoIndexScoreN=twoIndexScoreN+"!!"+twoIndexName+"_"+twoScore+"_"+1;
                    }
                }

                AvgSchool avgSchool1 = new AvgSchool();
                avgSchool1.setSchoolid(teachers.getTeacherschool());
                avgSchool1.setTwoindexscore(twoIndexScoreN);
                avgSchool1.setStutwoindexscore(twoIndexScoreN);

                int a = teacherService.insertAvgSchool(avgSchool1);
                if (a > 0) {
                    //System.out.println("成功");
                } else {
                    map.put("code", 207);
                    map.put("message", "添加学校平均分失败");
//                    map.put("data", "");
                    return map;
                }

            } else {
                map.put("code", 208);
                map.put("message", "学校查询失败");
//                map.put("data", "");
                return map;
            }
        }
//            //将此次评价分数整合到avg_college表
//
        if (teachers != null) {
            AvgCollege avgCollege = teacherService.selectAvgCollege(teachers.getTeachercollege());
            AvgCollege avgCollege1 = new AvgCollege();
            if (avgCollege != null) {

                String Twoindexscore1="";
                String studentTwoindexscore1="";
                String[] indexScores=indexScore.split(",");
                for (int c=0;c<indexScores.length;c++) {
                    String twoIndexName = indexScores[c].split("!")[1];//这次评价的二级指标名
                    float twoScore = Float.parseFloat(indexScores[c].split("!")[2]);//二级指标得分
                    if (avgCollege.getTwoindexscore() != null) {

                        String[] Twoindexscores = avgCollege.getTwoindexscore().split("!!");//学校表中已经有的二级指标；双感叹号分割
                        String[] studentTwoindexscores = avgCollege.getStutwoindexscore().split("!!");//学生评价已有的二级指标；双感叹号分割

                        List<String> list=new ArrayList<String>();
                        List<String> list1=new ArrayList<String>();

                        //学校总的二级指标评价统计
                        for (int a = 0; a < Twoindexscores.length; a++) {
                            String[] Twoindexscore = Twoindexscores[a].split("_");
                            String twoIndex = Twoindexscore[0];//已有的二级指标名
                            float score = Float.parseFloat(Twoindexscore[1]);//总分数
                            int number = Integer.parseInt(Twoindexscore[2]);//总人数

                            list.add(twoIndex);

                            if (twoIndex.equals(twoIndexName)) {
                                score = score + twoScore;
                                number = number + 1;

                                if (Twoindexscore1.equals("")) {
                                    Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }else {
                                if (Twoindexscore1.equals("")) {
                                    Twoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    Twoindexscore1 = Twoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }
                        }
                        if (!list.contains(twoIndexName)){
                            if (Twoindexscore1.equals("")) {
                                Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                            } else {
                                Twoindexscore1 = Twoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                            }
                        }


                        //学校学生评价的二级指标评价统计
                        for (int a = 0; a < studentTwoindexscores.length; a++) {
                            String[] Twoindexscore = studentTwoindexscores[a].split("_");
                            String twoIndex = Twoindexscore[0];//已有的学生评价二级指标名
                            float score = Float.parseFloat(Twoindexscore[1]);//总分数
                            int number = Integer.parseInt(Twoindexscore[2]);//总人数

                            list1.add(twoIndex);

                            if (twoIndex.equals(twoIndexName)) {
                                score = score + twoScore;
                                number = number + 1;

                                if (studentTwoindexscore1.equals("")) {
                                    studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }else {
                                if (studentTwoindexscore1.equals("")) {
                                    studentTwoindexscore1 = twoIndex + "_" + score + "_" + number;
                                } else {
                                    studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndex + "_" + score + "_" + number;
                                }
                            }
                        }
                        if (!list1.contains(twoIndexName)){
                            if (studentTwoindexscore1.equals("")) {
                                studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                            } else {
                                studentTwoindexscore1 = studentTwoindexscore1 + "!!" + twoIndexName + "_" + twoScore + "_" + 1;
                            }
                        }

                    } else {
                        Twoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                        studentTwoindexscore1 = twoIndexName + "_" + twoScore + "_" + 1;
                    }
                }

                avgCollege1.setSchoolcollegeid(avgCollege.getSchoolcollegeid());
                avgCollege1.setTwoindexscore(Twoindexscore1);
                avgCollege1.setStutwoindexscore(studentTwoindexscore1);

                int a = teacherService.updateAvgCollege(avgCollege1);
                if (a > 0) {
                    //System.out.println("成功");
                } else {
                    map.put("code", 209);
                    map.put("message", "修改学院平均分失败");
//                    map.put("data", "");
                    return map;
                }
            } else {
                String[] indexScores=indexScore.split(",");
                String twoIndexScoreN="";
                for (int e=0;e<indexScores.length;e++){

                    String twoIndexName = indexScores[e].split("!")[1];//二级指标名
                    float twoScore = Float.parseFloat(indexScores[e].split("!")[2]);//二级指标得分

                    if (twoIndexScoreN.equals("")){
                        twoIndexScoreN=twoIndexName+"_"+twoScore+"_"+1;
                    }else {
                        twoIndexScoreN=twoIndexScoreN+"!!"+twoIndexName+"_"+twoScore+"_"+1;
                    }
                }

                avgCollege1.setSchoolcollegeid(teachers.getTeachercollege());
                avgCollege1.setTwoindexscore(twoIndexScoreN);
                avgCollege1.setStutwoindexscore(twoIndexScoreN);

                int a = teacherService.insertAvgCollege(avgCollege1);
                if (a > 0) {
                    //System.out.println("成功");
                } else {
                    map.put("code", 209);
                    map.put("message", "添加学院平均分失败");
//                    map.put("data", "");
                    return map;
                }
            }

        } else {
            map.put("code", 210);
            map.put("message", "学院查询失败");
//            map.put("data", "");
            return map;
        }
        //添加到学生评价表中
        StudentEvaluate studentEvaluate = new StudentEvaluate();
        studentEvaluate.setStudentid(studentId);
        studentEvaluate.setByevaluatepersonid(byEvaluatePersonId);
        studentEvaluate.setEvaluatelabel(evaluateLabel);
        studentEvaluate.setEvaluatetotalpoints(twoIndexScore);
        studentEvaluate.setEvaluatetime(evaluateTime);
        studentEvaluate.setIndexscore(indexScore);
        studentEvaluate.setColleaguename(teachers.getTeachercollege());
        studentEvaluate.setStudentmajor(student.getStudentmajor());
        studentEvaluate.setStudentname(student.getStudentname());
        studentEvaluate.setStudentgrade(student.getStudentclasss());//年级
        studentEvaluate.setTeachername(teachers.getTeachername());//教师名
        studentEvaluate.setCourseid(courseId);//课程id
        studentEvaluate.setCoursename(courseName);//课程名
        studentEvaluate.setCoursecollege(course.getCoursecollege());//开课学院
        studentEvaluate.setSchoolname(student.getStudentschool());//学校
        studentEvaluate.setWeeknum((int)weekNum);//周数

        int b = evaluateTeacherService.insertStudentEvaluation(studentEvaluate);
        if (b > 0) {
            //添加日志！！
            //操作内容
            String logContent = "学生标签评价“" + byEvaluatePersonId + "”成功";
            //System.out.println(logContent);
            logController.logStudent(logContent, studentId);

            StudentPushLabel studentPushLabel=new StudentPushLabel();
            studentPushLabel.setPushid(pushId);
            studentPushLabel.setStudentid(studentId);
            studentPushLabel.setPushtime(pushTime);
            studentPushLabel.setTwoindexname(labelThreeIndexes.get(0).getTwoindexname());
            studentPushLabel.setSubmittime(evaluateTime);

            stuCourseLabelService.insertStudentPushLabel(studentPushLabel);

        } else {
            System.out.println("评价失败");
            map.put("code", 400);
            map.put("message", "评价失败");
//            map.put("data", null);
            return map;
        }

        System.out.println("评价成功");
        map.put("code", 200);
        map.put("message", "评价成功");

        StudentCount studentCount = studentCountService.selectByPrimaryKey(studentId);
        StudentCount studentCount1 = new StudentCount();
        if (studentCount != null) {
            studentCount1.setAnswerevaluatenum(studentCount.getAnswerevaluatenum() + 1);
            studentCount1.setStudentid(studentId);
            studentCountController.add(studentCount1, 1);
        } else {
            studentCount1.setAnswerevaluatenum(1);
            studentCount1.setStudentid(studentId);
            studentCountController.add(studentCount1, 0);
        }

        if (studentIntegralController.addIntegral(studentId, "evaluate", 3) != null) {
            map.put("integral", "评价成功积分加+3");
        } else {
            map.put("integral", "0");
        }

        return map;
    }



    /**
     * 查看老师的标签top10
     * @param request
     * @return
     */
    @RequestMapping(value = "selectLabelTopTen")
    public synchronized
    @ResponseBody
    Map<String, Object> selectLabelTopTen(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Integer> map1 = new HashMap<String, Integer>();
        Map<String, Object> map2 = null;
        List<Map> mapList=new ArrayList<Map>();

        String teacherId=request.getParameter("teacherId");//教师id

        TeacherRanking teacherRanking=teacherService.selectTeacherRanking(teacherId);
//        System.out.println("为空吗？？"+teacherRanking+"   教师id："+teacherId);
        if (teacherRanking!=null&&teacherRanking.getMylabelrank()!=null){

            String[] labelRankNums=teacherRanking.getMylabelrank().split("!!");
            for (String s:labelRankNums){
                String[] labelRankNum=s.split("_");
                map1.put(labelRankNum[0],Integer.parseInt(labelRankNum[1]));//指标为key,数量为value
            }

            //排序
            List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(map1.entrySet());
            Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
                public int compare(Map.Entry<String, Integer> o1,
                                   Map.Entry<String, Integer> o2) {
                    return ( o2.getValue()-o1.getValue());
                }
            });

            if (list.size()>=10){
                for (int a=0;a<10;a++){
                    map2=new HashMap<String, Object>();
                    Map.Entry<String,Integer> entry=list.get(a);
                    map2.put("labelName",entry.getKey());
                    map2.put("labelTop", entry.getValue());

                    mapList.add(map2);
                }
            }else {
                for (int a=0;a<list.size();a++){
                    map2=new HashMap<String, Object>();
                    Map.Entry<String,Integer> entry=list.get(a);
                    map2.put("labelName",entry.getKey());
                    map2.put("labelTop",entry.getValue());

                    mapList.add(map2);
                }
            }

            map.put("code", 200);
            map.put("message", "top查询成功");
            map.put("data",mapList);
        }else {
            map.put("code", 201);
            map.put("message", "暂无标签");
//            map.put("data","");
        }

        return map;
    }



    /**
     * 查看对老师的学生评价
     *
     * @param request
     * @return
     */

    @RequestMapping(value = "studentEvaluation")
    public synchronized
    @ResponseBody
    Map<String, Object> studentEvaluation(HttpServletRequest request) {
        Map<String,Object> map=new HashMap<String, Object>();
        Map<String,Object> map0=new HashMap<String, Object>();
        List<Map> mapList=new ArrayList<Map>();
        Map<String,Object> map1=null;
        LabelTwoIndex labelTwoIndex=null;

        String teacherId=request.getParameter("teacherId");//教师id

        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(teacherId, token);
        if (teacherData==null){
            map.put("code", 205);
            map.put("message", "您暂无权限做此操作");
           // map.put("data", "");
            return map;
        }


        TeacherRanking teacherRanking=teacherService.selectTeacherRanking(teacherId);
        if (teacherRanking!=null) {
            int ranking = teacherService.calculateTeacherRanking(teacherId) + 1;//比当前老师得分多的人数 + 1 = 该老师的排名
            map0.put("teacherRanking", ranking);//排名
        }else {
            map0.put("teacherRanking",0);
        }
        AvgSchool avgSchool=teacherService.selectAvgSchool();
        if (avgSchool!=null&&avgSchool.getTwoindexscore()!=null){
            String [] twoIndexNumScores=avgSchool.getTwoindexscore().split("!!");

            float sum=0f;//总分

            for (String s:twoIndexNumScores){

                String[] twoIndexNumScore=s.split("_");
//                    String twoIndexName=twoIndexNumScore[0];//二级指标名
                float twoIndexScore=Float.parseFloat(twoIndexNumScore[1])/Float.parseFloat(twoIndexNumScore[2]);//总分/人数=该二级指标的分数

                sum+=twoIndexScore;
            }
            float score=(float) (Math.round(sum/twoIndexNumScores.length * 100))/100;
            map0.put("schoolScore",score);//学校分
        }else {
            map0.put("schoolScore",0);
        }

        Teacher teacher=teacherService.serlectTeacher(teacherId);
        if (teacher!=null&&teacher.getTeachercollege()!=null){

            AvgCollege avgCollege=teacherService.selectAvgCollege(teacher.getTeachercollege());

            if (avgCollege!=null&&avgCollege.getTwoindexscore()!=null){

//                System.out.println(avgCollege.getSchoolcollegeid()+"   进入查询学院分："+avgCollege.getTwoindexscore());
                String [] twoIndexNumScores=avgCollege.getTwoindexscore().split("!!");

                float sum=0f;//总分

                for (String s:twoIndexNumScores){

                    String[] twoIndexNumScore=s.split("_");
//                    String twoIndexName=twoIndexNumScore[0];//二级指标名
                    float twoIndexScore=Float.parseFloat(twoIndexNumScore[1])/Float.parseFloat(twoIndexNumScore[2]);//总分/人数=该二级指标的分数

//                    System.out.println("二级指标："+twoIndexNumScore[0]+"====得分："+twoIndexScore);
                    sum+=twoIndexScore;
//                    System.out.println("   =和："+sum);
                }
                float score=(float) (Math.round(sum/twoIndexNumScores.length * 100))/100;
                map0.put("collegeScore",score);//学院分
            }else {
//                System.out.println("进入else");
                map0.put("collegeScore",0);//学院分
            }
        }


        String packageName="教评";

        List<LabelIndex> labelIndexList=labelService.selectByPackageName(packageName);

        if (labelIndexList.size()>0){

            for (LabelIndex labelIndex:labelIndexList){

                if (labelIndex.getIndexid()!=5) {//不要‘学校教学质量总体满意度评价’这个指标
                    map1 = new HashMap<String, Object>();

                    labelTwoIndex = new LabelTwoIndex();
                    labelTwoIndex.setIndexname(labelIndex.getIndexname());

                    List<LabelTwoIndex> labelTwoIndexList = labelService.selectBylabelName(labelTwoIndex);//通过一级指标找到二级指标

                    List<String> twoIndexNames = new ArrayList<String>();
                    if (labelTwoIndexList.size() > 0) {
                        for (LabelTwoIndex labelTwoIndex1 : labelTwoIndexList) {
                            twoIndexNames.add(labelTwoIndex1.getTwoindexname());
                        }
                    }
                    map1.put("indexName", labelIndex.getIndexname());
                    map1.put("twoIndexName", twoIndexNames);

                    mapList.add(map1);
                }
            }
        }else {
            map.put("code", 201);
            map.put("message", "指标查询失败");
//            map.put("data", "");
        }
        map0.put("label",mapList);

        map.put("code", 200);
        map.put("message", "指标查询成功");
        map.put("data", map0);

        return map;
    }


    /**
     * 查看对老师学生评价的二级指标
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "studentEvaluationTwoIndex")
    public synchronized
    @ResponseBody
    Map<String, Object> studentEvaluationTwoIndex(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> map1 =null;
        List<Map> mapList=new ArrayList<Map>();
        List<String> stringList=new ArrayList<String>();

        String teacherId=request.getParameter("teacherId");
        String indexName=request.getParameter("indexName");//传入一级指标
        String token=request.getParameter("token");

        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(teacherId, token);
        if (teacherData==null){
            map.put("code", 205);
            map.put("message", "您暂无权限做此操作");
           // map.put("data", "");
            return map;
        }

        LabelTwoIndex labelTwoIndex=new LabelTwoIndex();
        labelTwoIndex.setIndexname(indexName);
        List<LabelTwoIndex> labelTwoIndexList=labelService.selectBylabelName(labelTwoIndex);//通过一级指标找到二级指标

        if (labelTwoIndexList==null){
            map.put("code", 201);
            map.put("message", "未找到该一级指标");
//            map.put("data", mapList);
            return map;
        }
        for(LabelTwoIndex labelTwoIndex1:labelTwoIndexList){
//                    System.out.print("   二级指标：" + labelTwoIndex1.getTwoindexname());
            stringList.add(labelTwoIndex1.getTwoindexname());
        }
        TeacherRanking teacherRanking=evaluateTeacherService.selecteMyAvg(teacherId);
        if (teacherRanking!=null){

            if (teacherRanking.getStudenttwoindexscore()!=null) {//学生评价不等于空
//                System.out.println("学生评价不为空");

                String[] twoIndexNumScores = teacherRanking.getStudenttwoindexscore().split("!!");
//                System.out.println();
                for (int a=0;a<twoIndexNumScores.length;a++){
                    map1=new HashMap<String, Object>();

                    String[] twoIndexNumScore=twoIndexNumScores[a].split("_");
                    String twoIndex=twoIndexNumScore[0];//二级指标
                    float twoIndexScore=Float.parseFloat(twoIndexNumScore[1])/Integer.parseInt(twoIndexNumScore[2]);//二级指标得分

//                    System.out.print("  已评价二级指标："+twoIndex);
                    if (stringList.contains(twoIndex)){

                        map1.put("twoIndexName",twoIndex);//二级指标名
                        map1.put("twoIndexScore",twoIndexScore);//二级指标得分
                        mapList.add(map1);
                        stringList.remove(twoIndex);
                    }
                }
                if (stringList.size()>0){
                    for (String s:stringList){
                        map1=new HashMap<String, Object>();

                        map1.put("twoIndexName",s);
                        map1.put("twoIndexScore",0);
                        mapList.add(map1);
                    }
                }


            }else {
                //学生评价等于空
//                System.out.println("学生评价为空");
                for(LabelTwoIndex labelTwoIndex1:labelTwoIndexList){
                    map1=new HashMap<String, Object>();

                    map1.put("twoIndexName",labelTwoIndex1.getTwoindexname());
                    map1.put("twoIndexScore",0);

                    mapList.add(map1);
                }
            }
            map.put("code", 200);
            map.put("message", "学生评价查询成功");
            map.put("data", mapList);
        }else {

            for(LabelTwoIndex labelTwoIndex1:labelTwoIndexList){
                map1=new HashMap<String, Object>();

                map1.put("twoIndexName",labelTwoIndex1.getTwoindexname());
                map1.put("twoIndexScore",0);

                mapList.add(map1);
            }
            map.put("code", 200);
            map.put("message", "学生评价查询成功");
            map.put("data", mapList);
        }

        return map;
    }





}
